package ds;

public class MyLinkedList {
    private Node head;

    public void add(Object value) {
        Node node = new Node(value);
        if (head == null) {
            head = node;
        } else {
            Node cur = head;
            while (cur.next != null) cur = cur.next;
            cur.next = node;
        }
    }

    public boolean remove(Object value) {
        Node dummy = new Node(null);
        dummy.next = head;
        Node prev = dummy, cur = head;
        while (cur != null) {
            if (cur.value.equals(value)) {
                prev.next = cur.next;
                head = dummy.next;
                return true;
            }
            prev = cur;
            cur = cur.next;
        }
        return false;
    }

    public Node getHead() { return head; }

    public static class Node {
        public Object value;
        public Node next;
        public Node(Object value) { this.value = value; }
    }
} 